package com.itheima.reggie.common;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Map;

//生成解析token
public class JwtUtil {
    //生成token
    public static String createToken(Map cliam) {
        return Jwts.builder()
                .setClaims(cliam)
                .signWith(SignatureAlgorithm.HS256, "reggie")
                .compact();
    }

    //解析token
    public static Map parseToken(String token) {
        try {
            return Jwts.parser()
                    .setSigningKey("reggie")
                    .parseClaimsJws(token)
                    .getBody();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
